#include "../../common/detail.hpp"
#include "../../client/rpc_client.hpp"

using tmh_rpc::client::RpcCaller;

void callback(const Json::Value &res)
{
    ILOG("callback result:%d", res.asInt());
}
int main()
{
    //启用了服务发现功能            地址是注册中心的地址
    tmh_rpc::client::RpcClient client(true, "127.0.0.1", 8080);
    Json::Value params, result;
    params["num1"] = 10;
    params["num2"] = 40;
    ILOG("num1=%d, num2=%d", params["num1"].asInt(), params["num2"].asInt());
    bool ret = client.call("Add", params, result);
    if (ret != false)
    {
        ILOG("Syn result:%d", result.asInt());
    }

    params["num1"] = 1;
    params["num2"] = 4;
    // 异步调用
    tmh_rpc::client::RpcCaller::JsonAsyncResponse res_future;
    ret = client.call("Add", params, res_future);
    if (ret != false)
    {
        result = res_future.get();
        ILOG("Asyn result:%d", result.asInt());
    }

    params["num1"] = -1;
    params["num2"] = -10;
    ret = client.call("Add", params, callback);
    DLOG("---------------------------\n");
    sleep(3);
    return 0;
}